import { defineConfig, loadEnv, ConfigEnv, UserConfig } from "vite";
import { wrapperEnv } from "./src/utils/getEnv";
import { resolve } from "path";
import generateVersionPlugin from './plugins/generateVersion';
import vueJsx from "@vitejs/plugin-vue-jsx";
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
  const env = loadEnv(mode, process.cwd());
	const viteEnv = wrapperEnv(env);
  return {
    base: '/',
    resolve: {
      alias: {
        "@": resolve(__dirname, "./src")
      }
    },
    server: {
      host: "0.0.0.0",
      port: viteEnv.VITE_PORT,
			open: viteEnv.VITE_OPEN,
      cors: true,
      proxy: {
        "/upfile": {
          target: 'https://mcs-hq.oss-cn-shenzhen.aliyuncs.com', // 文件上传接口代理
          changeOrigin: true,
          rewrite: path => path.replace("/upfile", "")
        },
        [viteEnv.VITE_URL_PREFIX]: {
          target: viteEnv.VITE_API_URL,
          changeOrigin: true,
          rewrite: path => path.replace(viteEnv.VITE_URL_PREFIX, "")
        }
      }
    },
    plugins: [
      vue(),
      vueJsx(),
      generateVersionPlugin()
    ]
  }
})